import { ElNotification , ElMessageBox  } from 'element-plus'
import nprogress from 'nprogress'
// 默认这个方法是成功提示 ,渲染html的提示dangerouslyUseHTMLString = true
export function toast(message , type="success" , dangerouslyUseHTMLString = true){
    ElNotification({
        message, //值都是通过传递进去的
        type,
        dangerouslyUseHTMLString,
        duration:3000 //1S=1000ms
    })
}

export function showModel(content = '提示内容',type = 'warning',title = ''){
    //表示返回得到的是一个对象
    return ElMessageBox.confirm(
    content,
    title,
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: type,
    }
  ) 
}

//显示全屏Loading
export function showFullLoading(){
  nprogress.start()
}

//隐藏全屏Loading
export function hideFullLoading(){
  nprogress.done()
}

//弹出输入框
export function showPrompt(tip,value = ''){
  return ElMessageBox.prompt(tip, '', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    inputValue:value
  })
}

//将qurey对象转化url参数
export function queryParams(query){
  let q=[]
  // ?limit=10&keyword=ceshi 如何拼接出来
  for (const key in query) {
      //传递的数据存在在进行拼接
      if(query[key]){
          //确保数据不会丢失
          q.push(`${key}=${encodeURIComponent(query[key])}`)
      }
  }
  //数据之间使用$来拼接
  let r= q.join("&")
  //存在数据就加上问号
  r = r?("?"+r):""
  return r
}

//上移
export function useArrayMoveUp(arr,index){
  swapArray(arr,index,index-1)
}

//下移
export function useArrayMoveDown(arr,index){
  swapArray(arr,index,index+1)
}

function swapArray(arr,index1,index2){
  arr[index1]=arr.splice(index2,1,arr[index1])[0]
  return arr;
}

// 排列组合选项值和选项列(算法)
export function cartesianProductOf(){
  return Array.prototype.reduce.call(arguments,function(a,b){
    var ret = [];
    a.forEach(function (a) {
      b.forEach(function (b){
        ret.push(a.concat([b]));
      });
    });
    return ret;
  }, [
    []
])
}